package com.pureut.equipment.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pureut.equipment.domain.EquipmentKnowledge;
import com.pureut.equipment.domain.dto.EquipmentKnowledgeDto;
import com.pureut.equipment.domain.vo.EquipmentKnowledgeVo;
import com.pureut.equipment.service.IEquipmentKnowledgeService;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description 设备知识库
 * @Date 23-04-23
 * @Author hl
 **/
@RestController
@RequestMapping("/knowledge")
public class EquipmentKnowledgeController extends BaseController {

    @Resource
    private IEquipmentKnowledgeService equipmentKnowledgeService;

    /**
     * 查询设备知识库
     */
    @SaCheckPermission("device:repair:knowledge:list")
    @GetMapping("/list")
    public TableDataInfo<EquipmentKnowledgeDto> list(EquipmentKnowledgeVo equipmentKnowledgeVo, PageQuery pageQuery) {
        return equipmentKnowledgeService.selectKnowledgeList(equipmentKnowledgeVo,pageQuery);
    }

    /**
     * 新增设备知识库
     */
    @SaCheckPermission("device:repair:knowledge:add")
    @Log(title = "设备知识库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> addPlan(@RequestBody EquipmentKnowledge equipmentKnowledge) throws Exception {
        return toAjax(equipmentKnowledgeService.insertEquipmentKnowledge(equipmentKnowledge));
    }

    /**
     * 修改设备知识库
     */
    @SaCheckPermission("device:repair:knowledge:edit")
    @Log(title = "设备知识库", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody EquipmentKnowledge equipmentKnowledge){
        return toAjax(equipmentKnowledgeService.updateEquipmentKnowledge(equipmentKnowledge));
    }

    /**
     * 根据编号获取详细信息
     */
    @SaCheckPermission("device:repair:knowledge:query")
    @GetMapping(value = "/{knowledgeId}")
    public R<EquipmentKnowledgeDto> getInfo(@PathVariable("knowledgeId") long knowledgeId)
    {
        return R.ok(equipmentKnowledgeService.selectKnowledgeById(knowledgeId));
    }

    /**
     * 删除设备知识库
     */
    @SaCheckPermission("device:repair:knowledge:remove")
    @Log(title = "设备知识库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{knowledgeId}")
    public R<Void> remove(@PathVariable("knowledgeId") long knowledgeId) {
        return toAjax(equipmentKnowledgeService.deleteKnowledgeById(knowledgeId));
    }

    /**
     * map列表
     * @return
     */
    @GetMapping("/list1")
    public  List<Map<String, String>> list1() {
        List<Map<String, String>> list = equipmentKnowledgeService.selectKnowledgeById1();
        return list;
    }

}
